Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
Is there a "use default parameter" argument syntax for functions?

If I have a function declared with two default parameters, like this:

const doSomething = (defaultVal = 'me default', useThis = false) => {
      /* ... */
};

And I want to call the function passing in an argument for the second parameter, but have the first argument just use the default value:

doSomething(???, true);

Is there some syntax for telling the function to use the default parameter, or does a real value need to be passed in?

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

Pass in undefined

const doSomething = (defaultVal = 'me default', useThis = false) => {
  console.log({ defaultVal, useThis });
};

doSomething(undefined, true)

about 4 years ago · Santiago Gelvez Report

0

There is no syntax or key for that purpose. You should use default parameters as last. For that example if useThis parameter will be given a value for everytime you can give useThis as first argument.

Alternatively you can give an object as parameter. Inside the function you can merge your template (default valued object) and argument object then use it in you function.

const fn = (props) => {

    const newProps = {
        defaultVal : "default",
        useThis : false,
        ...props
    }

}
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!